/*
 * License: BSD (revised/modified)
 * Copyright: 2007 by Luis Rei
 */
 
#include "NeuralNet.h"

using namespace std;

int main(void) {
	NeuralNet *nn, *n2;
	Sig s;
	double *probs;
	double *sigArr;
	string test = "rec/x-12.bmp";
	int res, ii, numRes;
	string trainPath = "train/";
	string testDir = "rec/";
	string savePath ="/tmp/nn";
		
	nn = new NeuralNet(30, 30000, 0.3, 0.1, 0.0001, trainPath);
	numRes = nn->getNum();
	probs = new double [numRes];
	res = nn->test(test, probs);

	for (ii = 0; ii < numRes; ii++)
		cout << nn->whoIs(ii) << ": " << probs[ii]*100 << "%" << endl;
	cout << "Result = " << nn->whoIs(res) << endl << endl << endl;

	nn->save(savePath);
	cout << endl << "Saved." << endl;
	cout.flush();

	n2 = new NeuralNet(savePath);
	
	cout << "Loaded." << endl << endl;
	cout.flush();
	
	res = n2->test(test, probs);

	for (ii = 0; ii < numRes; ii++)
		cout << n2->whoIs(ii) << ": " << probs[ii]*100 << "%" << endl;
	cout << "Result = " << n2->whoIs(res) << endl << endl << endl;
	
	//
	cout << endl;
	
	test = "rec/luisrei-12.bmp";
	savePath = "/tmp/luisrei";
	s.load(test);
	s.saveNormalized(savePath);
	s.saveProjections(savePath);
	sigArr = s.toArray();
	
	ii = 0;
	while (sigArr[ii] != -1) {
		cout << sigArr[ii];
		ii++;
	}
	cout << endl;
	
	/*
	res = nn->testDir(testDir, &ii);
	cout << "FULL TEST RESULT = " << res << "/" << ii << endl;
	*/
	return 0;
}
